package cn.tl.user.service.impl;

import cn.tl.base.exception.BusinessException;
import cn.tl.base.service.impl.BaseServiceImpl;
import cn.tl.user.domain.LoginInfo;
import cn.tl.user.domain.dto.UserDto;
import cn.tl.user.mapper.LoginInfoMapper;
import cn.tl.user.service.ILoginInfoService;
import cn.tl.utils.MD5Utils;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginInfoServiceImpl extends BaseServiceImpl<LoginInfo> implements ILoginInfoService {
    @Autowired
    private LoginInfoMapper loginInfoMapper;
    @Override
    public LoginInfo login(UserDto userDto) throws BusinessException {
       LoginInfo loginInfo =  loginInfoMapper.findByAccount(userDto.getPhone());
        System.out.println(loginInfo);
       if(loginInfo==null){
           throw new BusinessException("用户名或密码错误");
       }
       //比较密码
        String byMd5 = MD5Utils.encrypByMd5(userDto.getPassword() + loginInfo.getSalt());
       if(!byMd5.equals((loginInfo.getPassword()))){
           throw new BusinessException("用户名或密码错误");
       }
       return loginInfo;
    }
}
